package club.emergency.wechat.feedback.operate.consumer.controller;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.utils.JsonConvert;
import club.emergency.wechat.feedback.operate.consumer.service.FeedbackOperateConsumer;
import club.emergency.wechat.model.feedback.Feedback;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: business
 * Package Name: club.emergency.wechat.feedback.operate.consumer.controller
 * Date: 2018/12/9
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Api("反馈操作接口")
@RestController
@RequestMapping("/feedback-operate")
public class FeedbackOperateController {

    private FeedbackOperateConsumer feedbackOperateConsumer;

    public FeedbackOperateController(FeedbackOperateConsumer feedbackOperateConsumer) {
        this.feedbackOperateConsumer = feedbackOperateConsumer;
    }

    @ApiOperation("新增反馈记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryNum", value = "反馈编号，0其他，1答案不正确，2题干错误", required = true, dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "category", value = "反馈类型", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "comment", value = "问题说明", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "questionId", value = "题目id", required = true, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "questionContent", value = "题目内容", required = true, dataType = "string", paramType = "query"),
    })
    @PostMapping("/save")
    public ResponseEntity save(
            @RequestParam("categoryNum") Integer categoryNum,
            @RequestParam("category") String category,
            @RequestParam("comment") String comment,
            @RequestParam("questionId") Long questionId,
            @RequestParam("questionContent") String questionContent
    ) {
        Feedback feedback = new Feedback();
        feedback.setCategoryNum(categoryNum);
        feedback.setCategory(category);
        feedback.setComment(comment);
        feedback.setQuestionId(questionId);
        feedback.setQuestionContent(questionContent);
        return new JsonConvert<ResponseEntity>().jsonDecode(feedbackOperateConsumer.save(feedback), ResponseEntity.class);
    }

    @ApiOperation("反馈标记处理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "long", paramType = "query"),
    })
    @PostMapping("/doDeal")
    public ResponseEntity doDeal(
            @RequestParam("id") Long id
    ) {
        return new JsonConvert<ResponseEntity>().jsonDecode(feedbackOperateConsumer.doDeal(id), ResponseEntity.class);
    }

}
